#!/bin/bash

# select an no root dir for exec this sh

# 1.create rc-local.service
(
cat <<EOF
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
 
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
 
[Install]
WantedBy=multi-user.target
EOF
) >./rc-local.service

sudo mv ./rc-local.service /etc/systemd/system/rc-local.service

# 2. init rc.local
(
cat <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "auto start test ok" > /usr/local/test.log
exit 0
EOF
) >./rc.local

sudo mv ./rc.local /etc/rc.local

# 3. last
sudo chmod 755 /etc/rc.local
sudo systemctl enable rc-local
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
